package com.hs.sentinelr.componet;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * redis工具类
 *
 * @Author lingNan
 * @Date 2021/8/22 9:43 下午
 **/
@Component
public class RedisUtil {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public Object getKey(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key, int i, int seconds, TimeUnit unit) {
        redisTemplate.opsForValue().set(key, i, seconds, unit);
    }

    public void incr(String key, int i) {
        redisTemplate.opsForValue().increment(key, i);
    }
}
